package anyVehicle;

import net.minecraft.src.Block;
import net.minecraft.src.Entity;
import net.minecraft.src.ModLoader;
import net.minecraft.src.RenderBlocks;
import net.minecraft.src.TileEntity;
import net.minecraft.src.TileEntitySpecialRenderer;

import org.lwjgl.opengl.GL11;

public class TileEntityRendererScaffold extends TileEntitySpecialRenderer {

	
	
	@Override
	public void renderTileEntityAt(TileEntity tileentity, double d, double d1, double d2, float f) {
		TileEntityScaffold scaffold = (TileEntityScaffold) tileentity;
		GL11.glPushMatrix();
		GL11.glTranslatef((float) d, (float) d1, (float) d2);
//		GL11.glRotatef(-f, 0.0F, 1.0F, 0.0F);
		ModLoader.getMinecraftInstance().renderEngine.bindTexture(ModLoader.getMinecraftInstance().renderEngine.getTexture("/terrain.png"));
		int numBlocksX = scaffold.getLengthBlocks() -1;
		int numBlocksY = scaffold.getHeightBlocks() -1;
		int numBlocksZ = scaffold.getWidthBlocks() -1;
		
		GL11.glTranslatef(0.5F, 0.5F, 0.5F);
		renderLine(scaffold, 1F, 0F, 0F, numBlocksX, false);
		GL11.glTranslatef(-numBlocksX, numBlocksY, 0F);
		renderLine(scaffold, 1F, 0F, 0F, numBlocksX, false);
		GL11.glTranslatef(-numBlocksX, 0F, numBlocksZ);
		renderLine(scaffold, 1F, 0F, 0F, numBlocksX, false);
		GL11.glTranslatef(-numBlocksX, -numBlocksY, 0F);
		renderLine(scaffold, 1F, 0F, 0F, numBlocksX, false);
		GL11.glTranslatef(-numBlocksX, -0F, -numBlocksZ);

		renderLine(scaffold, 0F, 1F, 0f, numBlocksY, false);
		GL11.glTranslatef(numBlocksX, -numBlocksY, 0F);
		renderLine(scaffold, 0F, 1F, 0f, numBlocksY, false);
		GL11.glTranslatef(0F, -numBlocksY, numBlocksZ);
		renderLine(scaffold, 0F, 1F, 0f, numBlocksY, false);
		GL11.glTranslatef(-numBlocksX, -numBlocksY, 0F);
		renderLine(scaffold, 0F, 1F, 0f, numBlocksY, false);
		GL11.glTranslatef(0F, -numBlocksY, -numBlocksZ);
		
		renderLine(scaffold, 0F, 0F, 1F, numBlocksZ, false);
		GL11.glTranslatef(numBlocksX, 0F, -numBlocksZ);
		renderLine(scaffold, 0F, 0F, 1F, numBlocksZ, false);
		GL11.glTranslatef(0F, numBlocksY, -numBlocksZ);
		renderLine(scaffold, 0F, 0F, 1F, numBlocksZ, false);
		GL11.glTranslatef(-numBlocksX, 0F, -numBlocksZ);
		renderLine(scaffold, 0F, 0F, 1F, numBlocksZ, false);
		GL11.glTranslatef(0F, -numBlocksY, -numBlocksZ);
		GL11.glPopMatrix();
	}



	private void renderLine(TileEntity entity, float xDir, float yDir, float zDir, int numBlocks, boolean renderTips) {
		if (renderTips) {
			rb.renderBlockOnInventory(Block.glass, 0, 0.5F);
		}
		GL11.glTranslatef(xDir, yDir, zDir);
		for (int i=1; i < numBlocks-1; i++) {
			rb.renderBlockOnInventory(Block.glass, 0, 0.5F);
			GL11.glTranslatef(xDir, yDir, zDir);
		}
		rb.renderBlockOnInventory(Block.glass, 0, 0.5F);
		GL11.glTranslatef(xDir, yDir, zDir);
		if (renderTips) {
			rb.renderBlockOnInventory(Block.glass, 0, 0.5F);
		}
	}
	

	public RenderBlocks rb = new RenderBlocks();


}
